package operation;

import book.BookList;

import java.util.Scanner;

public class BackBook implements Ioperation{
    public void work(BookList bookList){
        while(true) {
            boolean isborrow=false;
            Scanner ip = new Scanner(System.in);
            System.out.println("输入要归还的书名：");
            String name = ip.nextLine();
            for (int i = 0; i < bookList.getNumber(); i++) {
                if (name.equals(bookList.getBook(i).getName())&&bookList.getBook(i).isBorrow()==true) {
                    System.out.println("归还成功");
                    bookList.getBook(i).setBorrow(false);
                    isborrow=true;
                    break;
                }
                else if (name.equals(bookList.getBook(i).getName())&&bookList.getBook(i).isBorrow()==false){
                    System.out.println("这本书未被借出...");
                    isborrow=true;
                    break;
                }

                if (i== bookList.getNumber()-1&&!isborrow)
                    System.out.println("没有找到这本书");
            }
            System.out.println("是否继续归还");
            System.out.println("1.归还  2.退出");
            int out = ip.nextInt();
            if (out == 2)
                break;
        }
    }
}
